package com.itheima.config;

import com.itheima.pojo.Apple;
import com.itheima.pojo.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration //声明是一个配置类
public class UserConfig {

    @Bean
    public Apple apple(){
        return new Apple();
    }
    //<bean id="user" />
    @Bean
    //通过Conditional注解来进行条件判断,如果为true,则创建userBean;false,则不创建
    //
    // @Conditional(ClassCondition.class)
    // @ConditionalOnMissingBean(Apple.class) //代表如果beanFactory没有apple bean则创建userbean
    //@ConditionalOnBean(Apple.class)  //代表如果beanFactory有apple bean则创建userbean
    //itheima364
    @ConditionalOnProperty(name = "itheima", havingValue = "364")
    public User user(){
        User user = new User();
        user.setName("张三");
        user.setAge(23);
        return user;
    }
}
